package com.xiaohai.wx.weather.service;


import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.xiaohai.wx.weather.dao.UserDao;
import com.xiaohai.wx.weather.dto.User;
import org.springframework.stereotype.Service;


@Service("UserService")
public class UserService {
	
	@Autowired
	UserDao userDao;
	
	public List<User> getAllConsumerFromDB() {
		List<User> userList = userDao.queryAllUser();
		return userList;
	}

	public void addOrReplaceConsumerToDB(User consumer) {
		userDao.addOrReplaceUser(consumer);
	}

	public void removeConsumerFromDB(String openId) {
		userDao.deleteUserById(openId);
	}	
	
	public User getUserFromDB(String openId){
		return userDao.queryUserByOpenId(openId);
	}
	
	public void addNewUser(String openId, String key){
		User user = new User();
		user.setOpenId(openId);
		user.setMapKey(key);
		user.setGuanzhuTime(new Date());
		this.addOrReplaceConsumerToDB(user);
	}

}
